package com.design.pattern.state.manager;

import com.design.pattern.state.Dto.OrderInfoDTO;
import com.design.pattern.state.impl.CanceledOrderState;
import com.design.pattern.state.impl.FinishedOrderState;
import com.design.pattern.state.impl.WaitForPayOrderState;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


/**
 * 订单状态管理器
 */
@Component
public class OrderStateManagerImpl implements OrderStateManager{

    @Autowired
    private WaitForPayOrderState waitForPayOrderState;
    @Autowired
    private CanceledOrderState canceledOrderState;
    @Autowired
    private FinishedOrderState finishedOrderState;


    /**
     * 创建订单实现
     * @param order 订单
     */
    @Override
    public void create(OrderInfoDTO order) {
        waitForPayOrderState.doTransition(order);
    }

    /**
     * 取消订单实现
     * @param order 订单
     */
    @Override
    public void cancel(OrderInfoDTO order) {
        canceledOrderState.doTransition(order);
    }

    /**
     * 确认收货实现
     * @param order 订单
     */
    @Override
    public void confirmReceipt(OrderInfoDTO order) {
        finishedOrderState.doTransition(order);
    }
}
